package com.akuhome.resource.controller;

import com.akuhome.resource.entity.Character;
import com.akuhome.resource.service.entity.CharacterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/character")
public class CharacterController {
    @Autowired
    private CharacterService characterService;

    @GetMapping
    public Object findAllCharacter(){
        return characterService.findAllCharacter();
    }

    @PostMapping
    public Object insertCharacter(@Validated @RequestBody Character character, BindingResult bindingResult){
        return characterService.insertCharacter(character);
    }

    @PutMapping
    public Object updateCharacter(@Validated @RequestBody Character character, BindingResult bindingResult){
        return characterService.updateCharacter(character);
    }

    @DeleteMapping("/{characterId}")
    public Object deleteCharacterById(@PathVariable Integer characterId){
        return characterService.deleteCharacterById(characterId);
    }

    @PostMapping("/auth")
    public Object enableAuthByCharacterId(Integer characterId,Long authCode){
        characterService.updateAuthByCharacterId(characterId,authCode);
        return null;
    }
}
